#-*- coding:utf-8 -*-
import ExcelUtils
import sys,os
from projectUtils import Project
import projectUtils
reload(sys)
sys.setdefaultencoding("utf-8")

def linkString(fileName):
	list1 = []
	file = open(fileName)
	for line in file:
		list1.append(line+os.linesep)
	file.close()
	linefeed = os.linesep
	str1=linefeed.join(list1)
	return str1

if __name__ == '__main__':
	# remove old report
	allFiles = os.listdir(".")
	for file in allFiles:
		if file.endswith(".xls"):
			os.remove(file)

	projectMap = {u"西城区干部评测系统":u"GBPC",u"面授PC":u"FSPC",u"良师通": u"MLS", u"三科APP": u"SANKE", u"易学易练APP": u"MES", u"易学易练PC": u"EXEL",u"2017校本研修管理平台":u"XBYXGL",u"新版培训平台":u"XBPX",u"衡阳教师发展网":u"HYFZW",u"三科教材":u"SKJC",u"微课评选大赛":u"YTYJ",u"通州教师研修网":u"TZJSW",u"培训平台v1.7.0":u"PX",u"xcs2013升级":u"XCS",u"渝中学分云平台":u"YUZHONG",u"微课大赛整体改版":u"WKDS",u"昆明市五华区教师研修网":u"KMWH",u"地方社区":u"SQ",u"直播平台":"LIVE"}

	projectName = ""
	version = ""
	testscope = ""
	testscope = linkString("testscope.txt")
	projectKey = ""
	issueSummary = ""
	issueSummary = linkString("issueSummary.txt")
	testenv = ""
	testenv = linkString("testenv.txt")
	

	if len(sys.argv) >= 2:
		projectName = unicode(sys.argv[1],"utf-8")
		print (projectName)
		version = unicode(sys.argv[2],"utf-8")
		print (version)
	else:
		print "error! please check your input"

	#projectKey = projectMap[unicode(projectName,"gbk")]
	projectKey = projectMap[projectName]
	print "projectKey is ",
	print projectKey
	# projectKey = "EXEL"
	Project(projectKey)
	allBug = projectUtils.getBug(projectKey, version, "all")
	openBug = projectUtils.getBug(projectKey, version, "open")
	detail = projectUtils.getBugDetail(projectKey,version)
	# print len(openBug)
	ExcelUtils.generateReport(projectName, version, testscope, issueSummary, detail, openBug, allBug,testenv)